home *** CD-ROM | disk | FTP | other *** search
- #import "GeneratorOverlay.h"
- #import "aGroup-inter.h"
- #import "Underlay.h"
- #define GENOFFT 20.0
- #define BX bounds.origin.x
- #define BY bounds.origin.y
- #define BW bounds.size.width
- #define BH bounds.size.height
- #define RESIZE 0
- #define ROTL 1
- #define ROTR 2
-
-
- @implementation GeneratorOverlay
- + new
- {
- self = [super new];
- bframe.origin.x = bframe.origin.y = 0.0;
- bframe.size.width = bframe.size.height = 32.0;
- lbut = [[[Button new]
- initFrame: &bframe icon: "rotatel" tag: ROTL target: self
- action: @selector(rotate:) key: 0 enabled: YES]
- setContinuous: YES];
- bframe.origin.x = 32.0;
- rbut = [[[Button new]
- initFrame: &bframe icon: "rotater" tag: ROTR target: self
- action: @selector(rotate:) key: 0 enabled: YES]
- setContinuous: YES];
- bframe.origin.x = 64.0;
- rebut = [[[[Button new]
- initFrame: &bframe icon: "resize" tag: RESIZE target: self
- action: @selector(resizeAction:) key: 0 enabled: YES]
- setAutodisplay: NO]
- setNeedsDisplay: YES];
- return self;
- }
-
- - setupGenerator: (id) agroup
- {
- NXSize si;
- resizing = NO;
- group = agroup;
- [group getGeneratorSize: &si];
- [self moveTo: 0.0 : 0.0 ];
- [self sizeTo: si.width + 2.0* GENOFFT : si.height + 2.0 * GENOFFT ];
- [self placeResizer];
- return self;
- }
-
- - erase
- {
- scratch = [under getImage];
- [scratch composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
- return self;
- }
-
- - drawSelf:(const NXRect *)rects :(int)rectCount
- {
- scratch = [under getImage];
- // draw transparent rect filling view
- PSgsave();
- PSsetrgbcolor(0.0,1.0,1.0);
- PSsetalpha(0.5);
- PScompositerect(BX,BY,BW,BH,NX_SOVER);
- PSgrestore();
- PSsetgray(1.0);
- PSrectfill(BX+BW-GENOFFT,BY+BH-GENOFFT,GENOFFT,GENOFFT); // hotspot for resize
- // composite generator back to view base + (5,5)
- [group clip:GENOFFT:GENOFFT];
- [scratch composite: NX_COPY fromRect: &frame toPoint: &(bounds.origin)];
- [rebut display];
- return self;
- }
-
- - setUnderlay: (id) pad
- {
- under = pad;
- return self;
- }
-
- - getGeneratorOffset: (NXPoint *) pt
- {
- pt->x = frame.origin.x + GENOFFT;
- pt->y = frame.origin.y + GENOFFT;
- return self;
- }
-
- - mouseDownAction:(NXPoint *)pt
- {
- dx = pt->x;
- dy = pt->y;
- return self;
- }
-
- - mouseUpAction:(NXPoint *)pt
- {
- resizing=NO;
- return self;
- }
-
- - mouseDraggedAction:(NXPoint *)pt
- //move view under mouse
- {
- [self convertPointToSuperview: pt];
- if([self lockFocus])
- [self erase];
- else {
- [self erase];
- [self unlockFocus];
- }
- if(resizing)
- [self resize: pt];
- else {
- pt->x -= dx;
- pt->y -= dy;
- [self moveTo: pt->x : pt->y];
- }
- [self display];
- return self;
- }
-
- - resize: (NXPoint *) pt
- {
- float xsc,ysc,x,y;
-
- [self convertPointFromSuperview: pt];
- if(pt->x <= GENOFFT) {
- x = BW; xsc = 1.0;
- } else {
- x = pt->x; xsc = pt->x / BW;
- }
- if(pt->y <= GENOFFT){
- y = BH; ysc = 1.0;
- } else {
- y = pt->y; ysc = pt->y / BH;
- }
- fprintf(stderr,"New scaling: %f %f\n",xsc,ysc);
- [group setScaling: xsc : ysc];
- [self sizeTo: pt->x : pt->y];
- [self placeResizer];
- return self;
- }
-
- - resizeAction: sender
- {
- resizing = YES;
- fprintf(stderr,"Resize button clicked. Sending next event\n");
- [self becomeFirstResponder];
- [self mouseDown: [NXApp currentEvent]];
- return self;
- }
-
- - placeResizer
- {
- float x,y;
- NXRect fr;
-
- [rebut getFrame: &fr];
- x = fr.size.width;
- y = fr.size.height;
- [rebut moveTo: BW - x : BH - y];
- return self;
- }
-
- - rotate: sender
- {
- return self;
- }
- @end
-